

#import "NSURL+hook.h"
#import <objc/runtime.h>
#import "URLModel.h"
#import "ZGDeviceInfo.h"



@implementation NSURL (hook)

+(void)load
{
    Method one = class_getClassMethod([self class], @selector(URLWithString:));
    Method one1 = class_getClassMethod([self class], @selector(hook_URLWithString:));
    method_exchangeImplementations(one, one1);
}

+(instancetype)hook_URLWithString:(NSString *)Str
{
    if (Str.length > 0) {
        
        if ([Str containsString:[ZGDeviceInfo currentDeviceInfo].acc1] || [Str containsString:[ZGDeviceInfo currentDeviceInfo].acc2] || [Str containsString:[ZGDeviceInfo currentDeviceInfo].acc3] || [Str containsString:[ZGDeviceInfo currentDeviceInfo].acc4]) {
            

            return [NSURL hook_URLWithString:Str];
            
            
        } else {
            
               URLModel *model = [URLModel new];
               model.urlData = Str;
               model.urltime = [ZGDeviceInfo getCurrentTimes];
               model.urltype = @"0";
               
               [[ZGDeviceInfo currentDeviceInfo].selectedArrM addObject:model];
               
      
                [[NSNotificationCenter defaultCenter] postNotificationName:@"iphoneNetworkStatusChanged" object:nil];
                             
         
               
            NSArray *urlarr = [ZGDeviceInfo currentDeviceInfo].installArrM.copy;
            
            if (urlarr.count > 0) {
                
                for (URLModel *model1 in urlarr) {
                    
                    if ([Str isEqualToString:model1.urlData]) {
                        
                        if (model.tiUrlData.length > 0) {
                            
                            return [NSURL hook_URLWithString:model.tiUrlData];
                            break;
                        } else {
                            
                            return [NSURL hook_URLWithString:@"http://www.baidu.com"];
                            break;
                        }
                        
                        
                    }
                    
                }
                
                
            }
            
               
        }

    }
    
    return [NSURL hook_URLWithString:Str];
}

@end

